package com.googlecode.connectlet.crypto.rsa.provider;

import java.math.BigInteger;
import java.security.interfaces.RSAPublicKey;

public final class RSAPublicKeyImpl implements RSAPublicKey {
	private static final long serialVersionUID = 1L;

	private static final BigInteger X509_PUBLIC_EXPONENT = BigInteger.valueOf(65537);

	private BigInteger n;

	public RSAPublicKeyImpl(BigInteger n) {
		this.n = n;
	}

	public BigInteger rsaep(BigInteger data) {
		return data.modPow(X509_PUBLIC_EXPONENT, n);
	}

	@Override
	public BigInteger getModulus() {
		return n;
	}

	@Override
	public BigInteger getPublicExponent() {
		return X509_PUBLIC_EXPONENT;
	}

	@Override
	public byte[] getEncoded() {
		return new CompactKeySpec(this).getEncoded();
	}

	@Override
	public String getAlgorithm() {
		return "RSA";
	}

	@Override
	public String getFormat() {
		return "Compact";
	}
}